package com.boful.convert.core.impl.utils;

import java.io.File;

import com.boful.convert.model.DiskFile;

public class VideoTooltipThumbnails {
	static File src = new File("/home/ligson/workspace/convert/clip2.mp4");
	static File thumbnailsDir = new File("/home/ligson/workspace/convert/test");
	
	static File ffmpeg = new File("/usr/bin/ffmpeg");
	static File mediaInfo = new File("/usr/bin/mediainfo");

	public static void generail(File videoFile, File thumbnailsDir,
			File vttFile, int duration, int width, int heigth) {

		DiskFile diskFile = new DiskFile(videoFile);

		if (!thumbnailsDir.exists()) {
			thumbnailsDir.mkdirs();
		}
		long timeLength = MediaInfoUtils.getDuration(
				mediaInfo.getAbsolutePath(), diskFile);
		int len = (int) Math.floor(timeLength / duration);
		for (int i = 0; i < len; i++) {
			// DiskFile src, String mencoderPath,
			// int width, int height, int position, DiskFile dest,
			// String ffmpegPath
			int position = i * duration;
			DiskFile destFile = new DiskFile(new File(thumbnailsDir, position
					+ "-" + width + "x" + heigth + ".png"));
			FFMpegUtils
					.videoScreenShot(diskFile, mediaInfo.getAbsolutePath(),
							width, heigth, position, destFile,
							ffmpeg.getAbsolutePath());
		}
	}
	
	public static void main(String[] args) {
		generail(src, thumbnailsDir, ffmpeg, 1, 1024, 768);
	}
}

